<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class userAction extends BackAction{
    
    public function actionLogin() {
        
        if(isset($_SESSION['user'])){
            $this->redirect('user');
        }
        
        if($this->postVar('username') && $this->postVar('password')){
            $username   = $this->postVar('username');
            $password   = md5($this->postVar('password'));
            $rs         = ORM_Finder::findOne(DB_USER, array('username'=>$username,'password'=>$password));
            if(!$rs){
                setFlashMsg('电子邮件地址或者密码是不正确的，请重试一次。');
                $this->redirect('user/login');
            }

            $_SESSION['user']   = $rs->toArray();
            $this->redirect('m/weibo');
        }
        $this->setPageTitle('会员中心');
        $this->render();
    }
    
    public function actionIndex() {
        echo 22;
        exit;
        /**
         * record at 2011-10-25 11:41 30a2c6069c44a7efde760013accd015b
         */

        $token   = 'd613f705519398c6d10f67cfe3ef26d8';
        $c  = new SaeTClientV2( WB_AKEY , WB_SKEY , $token);
        $re = $c->followers_by_id('2350462347', 0, 200);
        if(array_key_exists('error', $re) && array_key_exists('error_code', $re)){
            echo $re['error'];
            exit;
        }
        
        $next_cursor    = $re['next_cursor'];
        $total_number   = $re['total_number'];
        while($next_cursor < $total_number){
            $urls[]         = 'https://api.weibo.com/2/friendships/followers.json?uid=1797810723&cursor='.$next_cursor.'&count=200';
            $next_cursor    = $next_cursor + 200;
        }

        $fp = new MultiHttpRequest($urls);
        $fp->set_access_token($token);
        $fp->set_users($re['users']);
        $fp->start();
        $_SESSION['users']  = $fp->get_users();
        echo count($_SESSION['users']);
        print_r($_SESSION['users']);
        exit;
    }
    
    function actionSave(){
        echo 111;
    }

    
    public function actionLogout() {
        session_destroy();
        $this->redirect('/');
    }
    
    public function actionModule() {
        $m = camelize($this->params['m']);
        $a = camelize($this->params['a']);
        $module_class = $m.'User';
        $module = new $module_class;
        $params = $this->params;
        if(empty ($a)){
            $a  = 'Index';
        }
        $params['module'] = $m;
        $params['action'] = $a;
        $module->setParams($params);
        $module->setView($this->view);
        $module->execute();
    }
}
?>
